package com.scsoft.dataacceptor.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.scsoft.dataacceptor.client.VocDbClient;
import com.scsoft.dataacceptor.client.VocLoginClient;

@Component
public class VocSummaCanTask {
	private static Logger log = LoggerFactory.getLogger("suma");
	private String user = "hnjc";
	@Value("${tcp.pass}")
	private String pass = "hnjc";
	@Value("${tcp.kind}")
	private String kind = "computer";
	@Value("${tcp.dbpass}")
	private String dbpass = "53681280";
	
	@Autowired
	private VocLoginClient loginClient;
	@Autowired
	private VocDbClient dbClient;
	
	@Scheduled(fixedDelay = 3600 * 1000, initialDelay = 1000)
	public void user_load() {
		String msg = "##|user_load|" + user + "|" + pass + "|" + kind + "|##\r\n";
		log.info("login msg:{}", msg);
		loginClient.doTcpRequest(msg.getBytes());
	}
	
	public void get_machlist1() {
		String word = "SELECT machine_site.machine_num, machine_site.machine_tel, machine_site.machine_man, machine_site.machine_address,"
				+ " machine_site.machine_lat, machine_site.machine_lng, machine_site.machine_phone, machine_site.machine_name,"
				+ " machine_site.machine_icon, machine_site.machine_infor, machine_site.create_date, machine_site.road_id,"
				+ " machine_site.online, machine_kind.kind_name, machine_kind.kind_property, machine_kind.kind_icon, machine_kind.kind_type, machine_kind.kind_man,"
				+ " machine_kind.kind_tel, machine_kind.kind_table_name, machine_kind.kind_column, machine_kind.kind_infor,"
				+ " company.company_name, company.company_icon, company.company_tel, company.company_email,"
				+ " company.company_man, company.company_address, company.company_lat, company.company_lng,"
				+ " company.company_infor, user_table.user_name, user_table.user_kind, user_table.uesr_icon, user_table.user_sex,"
				+ " user_table.user_tel, user_table.user_infor, user_table.create_date AS user_date, machine_site.ID, machine_kind.kind_tab, machine_site.camera, machine_site.machine_kind, machine_kind.kind_column_piont, machine_kind.kind_column_length"
				+ " FROM  machine_site INNER JOIN" + " company ON machine_site.machine_company = company.ID INNER JOIN"
				+ " machine_kind ON machine_site.machine_kind = machine_kind.ID INNER JOIN"
				+ " user_table ON company.ID = user_table.user_company" + " WHERE (user_table.user_name = '" + user
				+ "') order by  machine_kind.kind_name asc";
		String oper = "get_machlist1";
		String msg = "##|sel_database|hnjc|" + dbpass + "|" + oper + "|" + word + "|" + kind + "|##\r\n";
		log.info("msg:{}", msg);
		dbClient.doTcpRequest(msg.getBytes());
	}
	
//	@Scheduled(cron = "0 0 * * * ?")
	@Scheduled(fixedDelay = 300 * 1000, initialDelay = 10 * 1000)
	public void refresh_mach_kind1() {
		String word = "SELECT machine_num, machine_kind, online, data_time, value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16, value17,value18, value19, value20, value21, value22, value23, value24, value25, value26, value27, value28 FROM machine_site where machine_num = '"
				+ 19012301 + "' and machine_kind ='" + 16 + "'";
		String oper = "refresh_mach_kind1";
		String msg = "##|sel_database|hnjc|" + dbpass + "|" + oper + "|" + word + "|" + kind + "|##\r\n";
		log.info("msg:{}", msg);
		dbClient.doTcpRequest(msg.getBytes());
	}


	public String getUser() {
		return user;
	}


	public void setUser(String user) {
		this.user = user;
	}


	public String getPass() {
		return pass;
	}


	public void setPass(String pass) {
		this.pass = pass;
	}


	public String getKind() {
		return kind;
	}


	public void setKind(String kind) {
		this.kind = kind;
	}


	public String getDbpass() {
		return dbpass;
	}


	public void setDbpass(String dbpass) {
		this.dbpass = dbpass;
	}


	public VocDbClient getDbClient() {
		return dbClient;
	}


	public void setDbClient(VocDbClient dbClient) {
		this.dbClient = dbClient;
	}
	
	
}
